package com.swiftops.common.util;

import com.swiftops.common.model.TreeEntity;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

public class TreeTest {

    @Test
    public void test() {
        List<TreeEntity> flatList = Arrays.asList(
                new TreeEntity("1", "0", "Root"),
                new TreeEntity("2", "1", "Child 1"),
                new TreeEntity("3", "1", "Child 2"),
                new TreeEntity("4", "2", "Grandchild 1"),
                new TreeEntity("5", "3", "Grandchild 2")
        );

        List<TreeEntity> roots = TreeUtils.buildTree(flatList, TreeEntity::getId, TreeEntity::getParentId, "0");

        System.out.println(roots);
    }
}
